package com.smarthome.ipc.command;

import org.springframework.stereotype.Service;

import com.smarthome.domain.ipc.IpcCodeEnum;
import com.smarthome.domain.ipc.IpcConstants;
import com.smarthome.domain.ipc.IpcResponse;
import com.smarthome.domain.ipc.req.HkIpcResidenceDoorOpRequest;
import com.smarthome.domain.ipc.res.HKIpcResidenceDoorResponse;
import com.smarthome.common.tools.BossCachedKeysUtil;
import com.smarthome.ipc.hk.HKMainService;
import com.smarthome.ipc.hk.demo.HCNetSDK;
import com.smarthome.ipc.hk.entity.NetDvrLoginV30Entity;

/**
 * 海康门口机状态服务类
 * 
 * @author add by denghw 2015/09/27
 *
 */
@Service(IpcConstants.IPC_COMMAND_RESIDENCE_DOOR_HK_STATUS)
public class HkNetWorkStateGet extends HKMainService {
	@Override
	protected void doCmd(HkIpcResidenceDoorOpRequest request, IpcResponse<?> response) {
		// TODO Auto-generated method stub
		// 1.设置返回对象
		HKIpcResidenceDoorResponse spresonse = new HKIpcResidenceDoorResponse();
		response = spresonse;
		// 2.获取唯一的操作句柄
		NetDvrLoginV30Entity clickObj = (NetDvrLoginV30Entity) localCache.get(BossCachedKeysUtil
				.getKey(BossCachedKeysUtil.MODULE_HK_TALKDOOR_DEVICE, request.getIp() + request.getDeviceId()));
		HCNetSDK.NET_DVR_WORKSTATE_V30 workState = clickObj.getM_strWorkState();
		if (workState == null) {
			rtnBackErrMsg(request.getDeviceId(), request.getCommand(),
					String.valueOf(clickObj.gethCNetSDK().NET_DVR_GetLastError()), "获取设备状态失败");
			spresonse.setIpcCodeObj(IpcCodeEnum.SYSTEM_ERROR);
			return;
		}

		// 3.获取设备状态
		if (workState.dwDeviceStatic == 0 && workState.dwLocalDisplay == 0) {
			spresonse.setStatus("0");
		} else {
			spresonse.setStatus(String.valueOf(workState.dwDeviceStatic));
		}

		// 4.成功
		spresonse.setIpcCodeObj(IpcCodeEnum.SYSTEM_SUCCESS);

	}

}
